<?php
/**
 * Created by PhpStorm.
 * User: PanChaoZhi
 * Date: 2017/1/25
 * Time: 15:23
 */

namespace frontend\controllers;


use common\models\Category;
use common\models\CategoryGroup;
use common\Yii01;
use yii\web\Controller;

class ListController extends Controller
{
    public function actionIndex($id = 1)
    {
        //注册成功以后跳转到这里
        /**
         * 这里要做的是：
         * 1、获取所有的分类组
         * 2、根据id 获取一个分类组
         * 3、获取每一个分类属于哪个分类组，涉及到表的关联查询
         * 4、检查登录用户是否关注了某个分类
         * 4、把数据渲染到视图中
         */
        $cate_group = CategoryGroup::find()->orderBy(['sort' => SORT_DESC])->all();

        $groups = CategoryGroup::findOne(['id' => $id]);

        $model = Category::find()
            ->joinWith("group")
            ->where(['status' => 1, 'category_group.id' => $id])
            ->orderBy(['category_group.sort' => SORT_DESC, 'category.sort' => SORT_DESC])
            ->asArray()
            ->all();
        //debug($cate_group);
        //exit;
        //debug($groups);
        //exit;
        //debug($model);
        //exit;

        $msg = false;
        /*if (Yii01::isHasCate()) {
            $msg = true;
        }*/

        return $this->render('index', [
            'cate_group' => $cate_group,
            'model' => $model,
            'groups' => $groups,
            'id' => $id,
            'msg' => $msg,
        ]);


    }
}